//
//  BKWidigitMannager.m
//  bestkeep
//
//  Created by windCould on 17/1/11.
//  Copyright © 2017年 utouu. All rights reserved.
//

#import "BKWidigitMannager.h"
#import "Mediator+BKMy.h"
#import "AppDelegate.h"
#import "Mediator+BKMain.h"
@implementation BKWidigitMannager

+(void)bkWidigitMannager:(BKWidigitMannager *)bkWidigitMannager   clickBtnAtIndex:(NSString *)index
{
    if (![BKWidigitMannager  islogin]) {
       
        UIViewController * pushVC = [BKWidigitMannager getCurrentViewController].visibleViewController;
        
        [[Mediator sharedInstance]userGoToLoginFromOrignalController:pushVC finishBlock:^{
          
        }];
        
        return;
    }
    switch ([index integerValue]) {
        case 0:
        {
            UIViewController * phoneCharged = [[Mediator sharedInstance] BKPhoneCardsViewController];
            [[self getCurrentViewController] pushViewController:phoneCharged animated:YES];
        }
            break;
        case 1:
        {
            UIViewController * systemVC = [[Mediator sharedInstance]BKSystemMessageVC];
            [[self getCurrentViewController] pushViewController:systemVC animated:YES];
        }
            break;
        case 2:
        {
            UIViewController *sign = [[Mediator sharedInstance] BKIntegralViewController];
            [[self getCurrentViewController] pushViewController:sign animated:YES];
        }
            break;
        case 3:
        {
            UIViewController * favorVC = [[Mediator sharedInstance] getMyFavorController];
            [[self getCurrentViewController] pushViewController:favorVC animated:YES];
        }
            break;
            
        default:
            break;
    }
}

+(BOOL)islogin
{
    Mediator *mediator = [Mediator sharedInstance];
    NSDictionary *dic = [mediator BKMyUserInfo];
    NSNumber *result = dic[BKMyUserIsLoginKey];
    if ([result intValue] == 0) {
        
        return NO;
    }
    
    return YES;
}

//获取当前控制器

+(UINavigationController *) getCurrentViewController
{
    UINavigationController *navigationController;
    
    
    AppDelegate  * delegate = (AppDelegate *)[[UIApplication  sharedApplication] delegate];
    UIWindow * window = delegate.window;
    
    UITabBarController *tabBarController = (UITabBarController *)window.rootViewController;
    
    if (tabBarController.selectedIndex == 0) {
        
        navigationController = window.rootViewController.childViewControllers.firstObject;
        
    }else if (tabBarController.selectedIndex == 1) {
        
        navigationController = window.rootViewController.childViewControllers[1];
        
    }else if (tabBarController.selectedIndex == 2) {
        
        navigationController = window.rootViewController.childViewControllers[2];
        
    }else if (tabBarController.selectedIndex == 3) {
        
        navigationController = window.rootViewController.childViewControllers[3];
        
    }else {
        
        navigationController = window.rootViewController.childViewControllers.firstObject;
    }
    
    return navigationController;
    
}


@end
